/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package com.l2jserver.gameserver.network.serverpackets;

import java.util.List;

import com.l2jserver.gameserver.instancemanager.CustomItemMallManager;

/**
 * @author ASUS
 */
public class ExBrProductList extends L2GameServerPacket
{
	
	private List<CustomItemMallManager.MallItem> shoplist;
	
	public ExBrProductList(List<CustomItemMallManager.MallItem> _col){
		shoplist = _col;
	}
	/*
	 * (non-Javadoc)
	 * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#writeImpl()
	 */
	@Override
	protected void writeImpl()
	{
		writeC(0xFE);
		writeH(0xD7);
		writeD(0);
		writeD(shoplist.size());
		for (CustomItemMallManager.MallItem item : shoplist){
			if (System.currentTimeMillis() > item.getEndTime())
				continue;
			
			writeD(item.getMallItemId());//mallItemId 
			writeH(item.getCategory());//category: 1 - enchant; 2 - supplies; 3 - decoration; 4 - package 5 - other
			writeD(item.getPoint());
			writeD(0);
			writeD(item.getSaleflag());//4 Popular - 2 Reccomended - 1 Event
			writeD((int) (item.getStartTime() / 1000));//In second represent
			writeD((int) (item.getEndTime() / 1000));//same as above
			writeC(127); // day week (127 = not daily goods)
			writeC(item.getStartHour());
			writeC(item.getStartMin());
			writeC(item.getEndHour());
			writeC(item.getEndMin());
			writeD(item.getStock());// buyed stock
			writeD(item.getMaxStock());// max stock
			writeD(0);//need 0 writed if version>479
			writeD(1);// Sale % or Min Level ?

			CustomItemMallManager.MallItemTemplate temp = item.getTemplate();
			int i = 0;
			for(CustomItemMallManager.MallItemTemplate.ItemPackage pk : temp.getItemPackage()){
				writeD(temp.getItemPackage().size() - i);
				writeD(pk.getItemId());
				writeD(pk.getCount());
				writeD(pk.getWeight());
				i++;
			}
			writeD(0); // ?
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#getType()
	 */
	@Override
	public String getType()
	{
		return "[S] FE:D7 ExBrProductList";
	}
	
}
